﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 文件名：ClsFeeReimDAL.cs
/// 作  者：SAM
/// 时  间：2007.01.18
/// 说  明：ClsFeeReimDAL类用于费用报销信息相关处理
/// </summary>
public class ClsFeeReimDAL
{
    #region  数据库连接字符串
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    #endregion

    #region  费用报销数据访问层主体部分

    // 获取费用报销主单信息
    public DataSet GetFeeReimDataSet(string UserID, int Type)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetFeeReimM", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        dat.SelectCommand.Parameters.Add("@u_log_id", SqlDbType.NVarChar, 60);
        dat.SelectCommand.Parameters["@u_log_id"].Value = UserID;
        dat.SelectCommand.Parameters.Add("@type", SqlDbType.Int, 4);
        dat.SelectCommand.Parameters["@type"].Value = Type;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    // 获取所有费用报销从表信息
    public DataSet GetFeeReimChildDataSet(string No)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetFeeReimD", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        dat.SelectCommand.Parameters.Add("@r_no", SqlDbType.NVarChar, 50);
        dat.SelectCommand.Parameters["@r_no"].Value = No;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    // 作废费用报销主表
    public Boolean DeleteInfo(int ID, int Type)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteFeeReimInfo", con);

        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@type", SqlDbType.Int, 4);
        com.Parameters["@type"].Value = Type;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    // 作废费用报销从表
    public Boolean DeleteChildInfo(int ID, int Type)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteFeeReimChildInfo", con);

        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@type", SqlDbType.Int, 4);
        com.Parameters["@type"].Value = Type;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    // 确认或取消确认费用报销
    public Boolean AuditOrOAuditFeeReimInfo(int ID, string UserID, int Type)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AuditOrOAuditFeeReimInfo", con);

        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@user", SqlDbType.NVarChar, 50);
        com.Parameters["@user"].Value = UserID;
        com.Parameters.Add("@type", SqlDbType.Int, 4);
        com.Parameters["@type"].Value = Type;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    // 新增或修改费用报销主表信息
    public Boolean AddOrUpdateInfo(int ID, string No, DateTime Date, string Dp_No, string bsccw, string bscjl, string bxr, string Oper, string Remark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddOrUpdateFeeReimInfo", con);

        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@r_no", SqlDbType.NVarChar, 50);
        com.Parameters["@r_no"].Value = No;
        com.Parameters.Add("@r_date", SqlDbType.DateTime, 8);
        com.Parameters["@r_date"].Value = Date;
        com.Parameters.Add("@dp_id", SqlDbType.NVarChar, 50);
        com.Parameters["@dp_id"].Value = Dp_No;
        com.Parameters.Add("@bsccw", SqlDbType.NVarChar, 30);
        com.Parameters["@bsccw"].Value = bsccw;
        com.Parameters.Add("@bscjl", SqlDbType.NVarChar, 30);
        com.Parameters["@bscjl"].Value = bscjl;
        com.Parameters.Add("@bxr", SqlDbType.NVarChar, 30);
        com.Parameters["@bxr"].Value = bxr;

        com.Parameters.Add("@oper", SqlDbType.NVarChar, 50);
        com.Parameters["@oper"].Value = Oper;
        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    // 新增或修改费用报销从表信息
    public Boolean AddOrUpdateChild(int ID, string r_no, string up_no, string im_no, decimal a_money, decimal b_money, decimal c_money, decimal d_money, string Remark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddOrUpdateFeeReimChildInfo ", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@r_no", SqlDbType.NVarChar, 30);
        com.Parameters["@r_no"].Value = r_no;
        com.Parameters.Add("@up_no", SqlDbType.NVarChar, 30);
        com.Parameters["@up_no"].Value = up_no;
        com.Parameters.Add("@im_no", SqlDbType.NVarChar, 30);
        com.Parameters["@im_no"].Value = im_no;

        com.Parameters.Add("@a_money", SqlDbType.Decimal);
        com.Parameters["@a_money"].Value = a_money;
        com.Parameters.Add("@b_money", SqlDbType.Decimal);
        com.Parameters["@b_money"].Value = b_money;
        com.Parameters.Add("@c_money", SqlDbType.Decimal);
        com.Parameters["@c_money"].Value = c_money;
        com.Parameters.Add("@d_money", SqlDbType.Decimal);
        com.Parameters["@d_money"].Value = d_money;

        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;


        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    #endregion

    #region  费用报销数据访问层其他部分

    #endregion
}
